package service

import (
	"server_cluster/http/model"

	"server_cluster/common/logger"
)

func (s *Service) GetAnnouncement() *model.AnnouncementData {
	dbAnnouncementList, err := s.d.QueryAnnouncementList()
	if err != nil {
		logger.Error("query announcement from db error:", err)
		return nil
	}
	gameAnnouncementList := make([]*model.Announcement, 0)
	activityAnnouncement := make([]*model.Announcement, 0)
	for _, dbAnnouncement := range dbAnnouncementList {
		switch dbAnnouncement.Type {
		case model.DbAnnouncementTypeSystem:
			gameAnnouncementList = append(gameAnnouncementList, &model.Announcement{
				Id:           int32(dbAnnouncement.Id),
				Title:        dbAnnouncement.Title,
				ImageResName: dbAnnouncement.ImageResName,
				ImageResBtn:  dbAnnouncement.ImageResBtn,
				Content:      dbAnnouncement.Content,
				IsShow:       dbAnnouncement.IsShow,
			})
		case model.DbAnnouncementTypeActivity:
			activityAnnouncement = append(activityAnnouncement, &model.Announcement{
				Id:           int32(dbAnnouncement.Id),
				Title:        dbAnnouncement.Title,
				ImageResName: dbAnnouncement.ImageResName,
				ImageResBtn:  dbAnnouncement.ImageResBtn,
				Content:      dbAnnouncement.Content,
				IsShow:       dbAnnouncement.IsShow,
			})
		}
	}
	return &model.AnnouncementData{
		GameAnnouncement:     gameAnnouncementList,
		ActivityAnnouncement: activityAnnouncement,
	}
}
